package algo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Test {

    public static void main(String args[]) throws IOException {

//        Scanner input = new Scanner(System.in);
//         while(input.hasNext()){
//             System.out.println(input.next());
//
//         }

        List<Integer> matrix = new ArrayList<>();
        for (String s : args) {
//            System.out.println(s);
            String[] arr = s.split(" ");
            for(String si : arr) {
                int x = Integer.parseInt(si);
//                System.out.println(x);
                matrix.add(x);
            }
        }

        int n = matrix.get(0);
        int m = matrix.get(1);
//        System.out.println(n+ " " +m);

        Map<Long, Integer> map = new HashMap<>();
        Set<Long> set = new HashSet<>();

        for (int x = 2; x < 2 + 2 * n; x += 2) {
            long index = getIndex(matrix.get(x), matrix.get(x + 1));
            int count = map.getOrDefault(index, 0);
            count += 1;
            map.put(index, count);
        }
        for (int x = 2 + 2 * n; x < matrix.size(); x += 2) {
            set.add(getIndex(matrix.get(x), matrix.get(x + 1)));
        }
//        for(long l : set){
//            System.out.println("set: " + l);
//        }

        PriorityQueue<int[]> queue = new PriorityQueue<>((a, b) -> {
            if (a[0] != b[0]) return b[0] - a[0];
            else if (b[1] != a[1]) return a[1] - b[1];
            else return a[2] - b[2];
        });

        for (Map.Entry<Long, Integer> entry : map.entrySet()) {
            long key = entry.getKey();
            int[] xy = getXAndY(key);
            queue.offer(new int[]{entry.getValue(), xy[0] + xy[1], xy[0]});
        }

        while (!queue.isEmpty()) {
            int[] tmp = queue.poll();
            int x = tmp[2];
            int y = tmp[1] - x;
//            System.out.println("queue: "+ x+" "+y+" count "+ tmp[0]);
            if (!set.contains(getIndex(x, y))) {
                System.out.println(x + " " + y);
                break;
            }
        }


        // System.out.println(n + m);
    }

    private static long getIndex(int x, int y) {

        return x * 10000000l + y;

    }

    private static int[] getXAndY(long v) {
        int[] res = new int[2];
        res[1] = (int) (v % 10000000l);
        res[0] = (int) (v / 10000000l);

        return res;
    }
}
